

--注册常规合成
register_crad_rule('克苏鲁·沉眠之主',{'旧日血兽','星之病疮','深渊之门','死灵之书','克苏鲁之触','拉莱耶血池','黄衣之主'})

local crads = {
    '古神低语',
    '低语信徒',
    '血肉祭坛',
    '旧印石碑',
    '旧日血兽',
    '星之病疮',
    '深渊之门',
    '死灵之书',
    '克苏鲁之触',
    '拉莱耶血池',
    '黄衣之主',
}

ac.game:event '天赋-检测合成'(function(_,hero)
    local count = hero:get_data('克苏鲁-计数',0)
    if count>=12 and hero:get_data('阿撒托斯之瞳')==nil then
        hero:set_data('阿撒托斯之瞳',true)
        for _,temp in ipairs(get_card_list(hero,'克苏鲁')) do
            local pz = temp['品质']
            if pz~='UR' and pz~='UR+' then
                hide_card(temp)
            end
        end
        ac.wait(10,function()
            hero:notify('英雄-获得天赋',hero,'阿撒托斯之瞳')
        end)
    end
end)

--入口
local mt = ac.skill['古神低语']
function mt:on_add(hero,player)
    self.timer_count = ac.loop(180*1000,function(t)
        local list = {}
        for _,temp in ipairs(get_card_list(hero,'克苏鲁')) do
            local pz = temp['品质']
            if pz~='UR' and pz~='UR+' then
                table.insert(list,temp)
            end
        end
        if #list>0 then
            local temp = table.random(list)
            hide_card(temp)
        end
    end)
    self:gc(self.timer_count)
end

function mt:on_card(hero,player)
    if hero[self.name] then
        return
    end
    hero[self.name] = true
    for _,name in ipairs(crads) do
        player:set_data(name,true)
    end

    player:event '卡池-添加卡组'(function(_,_,pool)
        for _,name in ipairs(crads) do
            pool[#pool+1] = name
        end
    end)
    hero:event '天赋-检测合成后'(function(trg)
        local haves = hero:get_data('拥有天赋表') or {}
        for _,name in ipairs(crads) do
            if not haves[name] then
                return
            end
        end
        trg:remove()
        self.timer_count:remove()
        hero:set_data('完成-计数',hero:get_data('完成-计数',0) + 1)
    end)
end

local mt = ac.skill['变异']
mt.temp = '攻击触发'
mt.odds = 20
mt.model1 = [[02bdda1989387bb49538ab1043c67a6d.mdl]]
function mt:on_run(hero,target)
    local hero = self.owner
    local count = hero:get_data('触手数量',0) + 1
    if hero:find_skill('原初混沌') then
        self:set_cd(0)
    end
    for a=1,count do
        local angle = math.random(360)
        local point1 = target:get_point()
        local point2 = point1 - {angle,150}
        local damage = hero:get('生命上限')*self.data3 / 100
        local effect = point2:effect{
            model = self.model1,
            angle = angle + 180,
            hide_when_remove = true,
            time = 1,
        }
        effect:play_animation('attack')
        ac.wait(400,function()
            hero:aoe_damage(point1,300,damage,self)
        end)
    end
end


local mt = ac.skill['触手强化']
function mt:on_add()
    local hero = self.owner
    hero:set_data('触手数量',hero:get_data('触手数量',0) + self.data1)
end

local mt = ac.skill['超级触手强化']
function mt:on_add()
    local hero = self.owner
    hero:set_data('触手数量',hero:get_data('触手数量',0) + self.data1)
end


local mt = ac.skill['血肉增生']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-击杀'(function()
        hero:add('生命上限',self.data1)
    end))
end

local mt = ac.skill['死寂之门']
function mt:on_card(hero,player)
    local temp = hero:find_skill('古神低语')
    if temp then
        temp.odds = temp.odds + self.data1
        self:gc(function()
            temp.odds = temp.odds - self.data1
        end)
    end
end


local mt = ac.skill['深渊鞭笞']
mt.temp = '攻击触发'
mt.count = 5
function mt:on_init()
    self.count = self.data1
end

function mt:on_run(hero,target)
    local temp = hero:find_skill('古神低语')
    if temp then
        temp:notify('on_run',target)
    end
end


local mt = ac.skill['血池腐化']
mt.model1 = [[634b489d5f0ec8b2cbb20e8064de6733.mdl]]
function mt:on_add(target)
    local hero = self.owner
    local damage = hero:get('生命上限')*self.data1/100 + hero:get('生命恢复') * self.data2/100
    local cool = 0
    self:gc(hero:event '单位-击杀'(function(_,_,target)
        if cool<ac.clock() then
            cool = ac.clock() + 1000
            local point1 = target:get_point()
            point1:effect{
                model = self.model1,
                size = 2,
            }:remove()
            hero:aoe_damage(point1,400,damage,self)
        end
    end))
end

local mt = ac.skill['苍白之王']
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(ac.loop(1000,function()
        local num = math.min(math.floor(hero:get('生命上限')/self.data1) * self.data2,self.data3)
        hero:add('基础攻击',num - count)
        count = num
    end))
    self:gc(function()
        hero:add('基础攻击', - count)
    end)
end



local mt = ac.skill['旧日支配者']
function mt:on_add()
    local hero = self.owner
    local count = 0
    for _,temp in ipairs(get_card_list(hero,'克苏鲁')) do
        local pz = temp['品质']
        if pz~='UR' and pz~='UR+' then
            hide_card(temp)
        end
    end
    self:gc(ac.loop(1000,function()
        local num = hero:get_data('克苏鲁-计数',0) * self.data1
        hero:add('生命恢复%',num - count)
        count = num
    end))
    self:gc(function()
        hero:add('生命恢复%', - count)
    end)
end


local mt = ac.skill['八方之触']
mt.temp = '攻击触发'
mt.cool = 60
mt.model1 = [[a4ddce4e8950fdbc50fc618b9bcdef58.mdl]]
function mt:on_run(hero,target)
    local damage = hero:get('生命上限')*self.data2 / 100
    local point1 = target:get_point()
    point1:add_effect(self.model1,1)
    ac.wait(400,function()
        hero:aoe_damage(point1,self.data1,damage,self)
    end)
end



local mt = ac.skill['盲目痴愚之神']

function mt:on_add()
    local hero = self.owner
    local time = 0.5
    self:gc(hero:add_effect(self.cast_art))
    self:gc(ac.loop(time * 500,function()
        local damage = hero:get(self['属性1']) * self.data1/100 * time
        hero:aoe_damage(hero,600,damage,self)
    end))
end



local mt = ac.skill['万物归墟']
mt.temp = '攻击触发'
mt.cool = 120
mt.model1 = [[857bd6920afd5ba4e08c1b92b6574d5d.mdl]]
function mt:on_run(hero,target)
    local damage = hero:get('生命上限')*self.data2 / 100
    local point1 = target:get_point()
    point1:effect{
        model = self.model1,
        time = 1,
    }
    hero:aoe_damage(point1,600,damage,self,function(unit)
        unit:add_buff '晕眩'{time = self.data1}
    end)
end


local mt = ac.skill['无序之主']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-造成伤害前'(function(_,_,_,data)
        local rate = math.random(self.data1,self.data2) - 100
        data:mul(rate)
    end))
    self:gc(hero:event '单位-受到伤害前'(function(_,_,_,data)
        local rate = math.random(self.data3,self.data4) - 100
        data:div(rate)
    end))
end